/**
 * @file XFooterView.java
 * @create Mar 31, 2012 9:33:43 PM
 * @author Maxwin
 * @description XListView's footer
 */
package com.mogujie.tt.utils;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mogujie.tt.R;

public class XListViewFooter extends LinearLayout {
	public final static int STATE_NORMAL = 0;
	public final static int STATE_READY = 1;
	public final static int STATE_LOADING = 2;
	public final static int STATE_SAN = 3;
	public final static int STATE_FOR = 4;
	public final static int STATE_FIN = 5;
	public final static int STATE_SIX = 6;

	private Context mContext;

	private View mContentView;
	private View mContentView1;
	private View mProgressBar;
	private TextView mHintView;
	private TextView Foot_text;
	
	public XListViewFooter(Context context) {
		super(context);
		initView(context);
	}
	
	public XListViewFooter(Context context, AttributeSet attrs) {
		super(context, attrs);
		initView(context);
	}

	
	public void setState(int state) {
		mHintView.setVisibility(View.INVISIBLE);
		mProgressBar.setVisibility(View.INVISIBLE);
		mHintView.setVisibility(View.INVISIBLE);
		if (state == STATE_READY) {
			mHintView.setVisibility(View.VISIBLE);
			mHintView.setText("松开刷新数据");
		} else if (state == STATE_LOADING) {
			mProgressBar.setVisibility(View.VISIBLE);
		} else if (state == STATE_SAN){
			mHintView.setVisibility(View.VISIBLE);
			mContentView.setVisibility(View.GONE);
			mContentView1.setVisibility(View.VISIBLE);
			Foot_text.setText("真的木有了~");
		}else if (state == STATE_FOR){
			mContentView.setVisibility(View.VISIBLE);
			mContentView1.setVisibility(View.GONE);
			mHintView.setVisibility(View.VISIBLE);
			mHintView.setText("查看更多");
		}else if (state == STATE_FIN){
			mContentView.setVisibility(View.GONE);
			mContentView1.setVisibility(View.VISIBLE);
			Foot_text.setText("他们太懒了，什么都没留下~");
		}else if (state == STATE_SIX){
			mContentView.setVisibility(View.GONE);
			mContentView1.setVisibility(View.GONE);
		}else {
			mHintView.setVisibility(View.VISIBLE);
			mHintView.setText("查看更多");
		}
	}
	
	public void setBottomMargin(int height) {
		if (height < 0) return ;
		LayoutParams lp = (LayoutParams)mContentView.getLayoutParams();
		lp.bottomMargin = height;
		mContentView.setLayoutParams(lp);
	}
	public int getBottomMargin() {
		LayoutParams lp = (LayoutParams)mContentView.getLayoutParams();
		return lp.bottomMargin;
	}
	/**
	 * normal status
	 */
	public void normal() {
		mHintView.setVisibility(View.VISIBLE);
		mProgressBar.setVisibility(View.GONE);
	}
	/**
	 * loading status 
	 */
	public void loading() {
		mHintView.setVisibility(View.GONE);
		mProgressBar.setVisibility(View.VISIBLE);
	}
	/**
	 * hide footer when disable pull load more
	 */
	public void hide() {
		LayoutParams lp = (LayoutParams)mContentView.getLayoutParams();
		lp.height = 0;
		mContentView.setLayoutParams(lp);
	}
	/**
	 * show footer
	 */
	public void show() {
		LayoutParams lp = (LayoutParams)mContentView.getLayoutParams();
		lp.height = LayoutParams.WRAP_CONTENT;
		mContentView.setLayoutParams(lp);
	}
	private void initView(Context context) {
		mContext = context;
		LinearLayout moreView = (LinearLayout)LayoutInflater.from(mContext).inflate(R.layout.xlistview_footer, null);
		addView(moreView);
		moreView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
		mContentView = moreView.findViewById(R.id.xlistview_footer_content);
		mContentView1 = moreView.findViewById(R.id.xlistview_footer_content1);
		mProgressBar = moreView.findViewById(R.id.xlistview_footer_progressbar);
		mHintView = (TextView)moreView.findViewById(R.id.xlistview_footer_hint_textview);
		Foot_text = (TextView) moreView.findViewById(R.id.footer_text);
	}
}
